package com.lfnyxy.service.imp;

import com.lfnyxy.dao.IndustryTypeDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.IndustryTypeEntity;
import com.lfnyxy.query.IndustryTypeQuery;
import com.lfnyxy.service.IndustryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndustryTypeServiceImp implements IndustryTypeService {
    @Autowired
    public IndustryTypeDao industryTypeDao;

    public int CreateItem(IndustryTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return industryTypeDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(IndustryTypeEntity entity) {
        if (entity != null) {
            if (CheckIsExist(entity)) {
                return -1;
            }
            return industryTypeDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <IndustryTypeEntity> QueryPageList(IndustryTypeQuery query) {
        int count = industryTypeDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return industryTypeDao.QueryPageList(query);
        }
        return null;
    }

    public List <IndustryTypeEntity> QueryAll() {
        return industryTypeDao.QueryAll();
    }

    public IndustryTypeEntity QueryItem(int Id) {
        if (Id > 0) {
            return industryTypeDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return industryTypeDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    @Override
    public List <DropVo> QueryDrop(IndustryTypeQuery query) {
        return industryTypeDao.QueryDrop(query);
    }

    private boolean CheckIsExist(IndustryTypeEntity entity) {
        if (entity != null) {
            return industryTypeDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}